<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch">
      <el-form-item label="参考" prop="name">
        <el-input v-model="queryParams.name" placeholder="请输入参考" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      
      <el-form-item label="供应商" prop="partnerId" >
        <el-select v-model="queryParams.partnerId" filterable placeholder="请选择供应商" clearable
          @keyup.enter.native="handleQuery" :filter-method="customerfilterMethod">
          <el-option v-for="item in customerdata" :key="item.id" :label="item.name" :value="item.id" />
        </el-select>
        <!-- <el-input v-model="queryParams.partnerId" placeholder="请输入客户" clearable @keyup.enter.native="handleQuery" /> -->
      </el-form-item>
      <el-form-item label="产品名称" prop="partName">
        <el-input v-model="queryParams.partName" placeholder="请输入产品名称" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="状态" prop="state">
        <el-select v-model="queryParams.state" filterable placeholder="请选择订单状态" clearable
          @keyup.enter.native="handleQuery">
          <el-option v-for="item in stateList" :key="item.id" :label="item.name" :value="item.id" />
        </el-select>
        <!-- <el-input v-model="queryParams.state" placeholder="请输入订单状态" clearable @keyup.enter.native="handleQuery" /> -->
      </el-form-item>
      <!-- <el-form-item label="来源" prop="origin">
        <el-input
          v-model="queryParams.origin"
          placeholder="请输入来源"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <el-form-item label="订单日期">
        <el-date-picker v-model="daterangeDateOrder" style="width: 240px" value-format="yyyy-MM-dd" type="daterange"
          range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期"></el-date-picker>
      </el-form-item>
      <!-- <el-form-item label="核准日期">
        <el-date-picker
          v-model="daterangeDateApprove"
          style="width: 240px"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></el-date-picker>
      </el-form-item> -->
      <!-- <el-form-item label="供应商id" prop="partnerId">
        <el-input
          v-model="queryParams.partnerId"
          placeholder="请输入供应商id"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <!-- <el-form-item label="Currency" prop="currencyId">
        <el-input
          v-model="queryParams.currencyId"
          placeholder="请输入Currency"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="状态" prop="state">
        <el-input
          v-model="queryParams.state"
          placeholder="请输入状态"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="发票数量" prop="invoiceCount">
        <el-input
          v-model="queryParams.invoiceCount"
          placeholder="请输入发票数量"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <!-- <el-form-item label="账单状态" prop="invoiceStatus">
        <el-input v-model="queryParams.invoiceStatus" placeholder="请输入账单状态" clearable @keyup.enter.native="handleQuery" />
      </el-form-item> -->
      <!-- <el-form-item label="Receptions" prop="pickingCount">
        <el-input
          v-model="queryParams.pickingCount"
          placeholder="请输入Receptions"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="计划日期">
        <el-date-picker
          v-model="daterangeDatePlanned"
          style="width: 240px"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></el-date-picker>
      </el-form-item>
      <el-form-item label="不含税总额" prop="amountUntaxed">
        <el-input
          v-model="queryParams.amountUntaxed"
          placeholder="请输入不含税总额"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="税额" prop="amountTax">
        <el-input
          v-model="queryParams.amountTax"
          placeholder="请输入税额"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <!-- <el-form-item label="订单总额" prop="amountTotal">
        <el-input v-model="queryParams.amountTotal" placeholder="请输入订单总额" clearable @keyup.enter.native="handleQuery" />
      </el-form-item> -->
      <!-- <el-form-item label="创建者" prop="createUid">
        <el-select v-model="queryParams.createUid" placeholder="请选择创建者" clearable>
          <el-option
            v-for="dict in dict.type.boshien_emp"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="Deliver To" prop="pickingTypeId">
        <el-input
          v-model="queryParams.pickingTypeId"
          placeholder="请输入Deliver To"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="组id" prop="groupId">
        <el-input
          v-model="queryParams.groupId"
          placeholder="请输入组id"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="创建日期">
        <el-date-picker
          v-model="daterangeCreateDate"
          style="width: 240px"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></el-date-picker>
      </el-form-item>
      <el-form-item label="最后更新人" prop="writeUid">
        <el-select v-model="queryParams.writeUid" placeholder="请选择最后更新人" clearable>
          <el-option
            v-for="dict in dict.type.boshien_emp"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="最后更新日期" prop="writeDate">
        <el-date-picker clearable
          v-model="queryParams.writeDate"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择最后更新日期">
        </el-date-picker> 
      </el-form-item>-->
      <!-- <el-form-item label="采购单号" prop="purchaseNum">
        <el-input
          v-model="queryParams.purchaseNum"
          placeholder="请输入采购单号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <!-- <el-form-item label="订单编号" prop="orderNum">
        <el-input
          v-model="queryParams.orderNum"
          placeholder="请输入订单编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <!-- <el-form-item label="公司电话" prop="telId">
        <el-input
          v-model="queryParams.telId"
          placeholder="请输入公司电话"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="公司邮箱" prop="emailId">
        <el-input
          v-model="queryParams.emailId"
          placeholder="请输入公司邮箱"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="编制" prop="createMen">
        <el-input
          v-model="queryParams.createMen"
          placeholder="请输入编制"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <!-- <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:perchase:add']"
        >新增</el-button>
      </el-col> -->
      <el-col :span="1.5">
        <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="AddIquirySheet"
         >新增询价单</el-button>
      </el-col>
      <!-- <el-col :span="1.5">
        <el-button type="success" plain icon="el-icon-edit" size="mini" :disabled="single" @click="handleUpdate"
          v-hasPermi="['system:perchase:edit']">修改</el-button>
      </el-col> -->
      <!-- <el-col :span="1.5">
        <el-button type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple" @click="handleDelete"
          v-hasPermi="['system:perchase:remove']">删除</el-button>
      </el-col> -->
      <el-col :span="1.5">
        <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport"
          >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="perchaseList" @selection-change="handleSelectionChange" @row-click="getDetail">
      <el-table-column type="selection" width="55" align="center" />
      <!-- <el-table-column label="id" align="center" prop="id" /> -->
      <el-table-column label="参考" align="center" prop="name" />
      <!-- <el-table-column label="来源" align="center" prop="origin" /> -->
      <el-table-column label="订单日期" align="center" prop="dateOrder" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.dateOrder, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <!-- <el-table-column label="核准日期" align="center" prop="dateApprove" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.dateApprove, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column> -->
      <el-table-column label="供应商" align="center" prop="partnerName" />
      <!-- <el-table-column label="Currency" align="center" prop="currencyId" /> -->

      <!-- <el-table-column label="采购信息" align="center" prop="notes" />
      <el-table-column label="发票数量" align="center" prop="invoiceCount" />-->

      <!-- <el-table-column label="Receptions" align="center" prop="pickingCount" />  -->
      <el-table-column label="预定交货日期" align="center" prop="datePlanned" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.datePlanned, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="不含税总额" align="center" prop="amountUntaxed" />
      <!-- <el-table-column label="税额" align="center" prop="amountTax" /> -->
      <el-table-column label="订单总额" align="center" prop="amountTotal" />
      <!-- <el-table-column label="账单状态" align="center" prop="invoiceStatus" /> -->
      <el-table-column label="账单状态" align="center" prop="invoiceStatus">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.invoice_state" :value="scope.row.invoiceStatus" />
        </template>
      </el-table-column>
      <el-table-column label="状态" align="center" prop="state">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.order_state" :value="scope.row.state" />
        </template>
      </el-table-column>
      <!-- <el-table-column label="创建者" align="center" prop="createUid">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.boshien_emp" :value="scope.row.createUid"/>
        </template>
      </el-table-column>
      <el-table-column label="Deliver To" align="center" prop="pickingTypeId" />
      <el-table-column label="组id" align="center" prop="groupId" />
      <el-table-column label="创建日期" align="center" prop="createDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="最后更新人" align="center" prop="writeUid">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.boshien_emp" :value="scope.row.writeUid"/>
        </template>
      </el-table-column>
      <el-table-column label="最后更新日期" align="center" prop="writeDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.writeDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column> -->
      <!-- <el-table-column label="采购单号" align="center" prop="purchaseNum" /> -->
      <!-- <el-table-column label="订单编号" align="center" prop="orderNum" /> -->
      <!-- <el-table-column label="公司电话" align="center" prop="telId" /> -->
      <!-- <el-table-column label="公司邮箱" align="center" prop="emailId" /> -->
      <!-- <el-table-column label="编制" align="center" prop="createMen" /> -->
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" @click.stop>
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-document" @click.stop="getDetail(scope.row)"
           >订单详情</el-button>
          <el-button size="mini" type="text" icon="el-icon-edit" @click.stop="EditSale(scope.row)" v-show="scope.row.state=='draft'"
           >修改</el-button>
          <!-- <el-button size="mini" type="text" icon="el-icon-edit" @click.stop="sureState(scope.row)"
            v-hasPermi="['system:perchase:edit']">确认采购订单</el-button>
            <el-button size="mini" type="text" icon="el-icon-edit" @click.stop="cancelState(scope.row)"
            v-hasPermi="['system:perchase:edit']">取消采购订单</el-button> -->
          <el-button size="mini" type="text" icon="el-icon-delete" @click.stop="handleDelete(scope.row)"
          v-hasRole="['admin']">删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />

    <!-- 添加或修改采购对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="800px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="150px">
        <el-form-item label="参考" prop="name">
          <el-input v-model="form.name" placeholder="请输入参考" />
        </el-form-item>
        <el-form-item label="来源" prop="origin">
          <el-input v-model="form.origin" placeholder="请输入来源" />
        </el-form-item>
        <el-form-item label="订单日期" prop="dateOrder">
          <el-date-picker clearable v-model="form.dateOrder" type="date" value-format="yyyy-MM-dd" placeholder="请选择订单日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="核准日期" prop="dateApprove">
          <el-date-picker clearable v-model="form.dateApprove" type="date" value-format="yyyy-MM-dd"
            placeholder="请选择核准日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="供应商id" prop="partnerId">
          <el-input v-model="form.partnerId" placeholder="请输入供应商id" />
        </el-form-item>
        <el-form-item label="Currency" prop="currencyId">
          <el-input v-model="form.currencyId" placeholder="请输入Currency" />
        </el-form-item>
        <el-form-item label="状态" prop="state">
          <el-input v-model="form.state" placeholder="请输入状态" />
        </el-form-item>
        <el-form-item label="采购信息" prop="notes">
          <el-input v-model="form.notes" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="发票数量" prop="invoiceCount">
          <el-input v-model="form.invoiceCount" placeholder="请输入发票数量" />
        </el-form-item>
        <el-form-item label="账单状态" prop="invoiceStatus">
          <el-input v-model="form.invoiceStatus" placeholder="请输入账单状态" />
        </el-form-item>
        <el-form-item label="Receptions" prop="pickingCount">
          <el-input v-model="form.pickingCount" placeholder="请输入Receptions" />
        </el-form-item>
        <el-form-item label="计划日期" prop="datePlanned">
          <el-date-picker clearable v-model="form.datePlanned" type="date" value-format="yyyy-MM-dd"
            placeholder="请选择计划日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="不含税总额" prop="amountUntaxed">
          <el-input v-model="form.amountUntaxed" placeholder="请输入不含税总额" />
        </el-form-item>
        <el-form-item label="税额" prop="amountTax">
          <el-input v-model="form.amountTax" placeholder="请输入税额" />
        </el-form-item>
        <el-form-item label="订单总额" prop="amountTotal">
          <el-input v-model="form.amountTotal" placeholder="请输入订单总额" />
        </el-form-item>
        <el-form-item label="创建者" prop="createUid">
          <el-select v-model="form.createUid" placeholder="请选择创建者">
            <el-option v-for="dict in dict.type.boshien_emp" :key="dict.value" :label="dict.label"
              :value="parseInt(dict.value)"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="Deliver To" prop="pickingTypeId">
          <el-input v-model="form.pickingTypeId" placeholder="请输入Deliver To" />
        </el-form-item>
        <el-form-item label="组id" prop="groupId">
          <el-input v-model="form.groupId" placeholder="请输入组id" />
        </el-form-item>
        <el-form-item label="创建日期" prop="createDate">
          <el-date-picker clearable v-model="form.createDate" type="date" value-format="yyyy-MM-dd" placeholder="请选择创建日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="最后更新人" prop="writeUid">
          <el-select v-model="form.writeUid" placeholder="请选择最后更新人">
            <el-option v-for="dict in dict.type.boshien_emp" :key="dict.value" :label="dict.label"
              :value="parseInt(dict.value)"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="最后更新日期" prop="writeDate">
          <el-date-picker clearable v-model="form.writeDate" type="date" value-format="yyyy-MM-dd"
            placeholder="请选择最后更新日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="采购单号" prop="purchaseNum">
          <el-input v-model="form.purchaseNum" placeholder="请输入采购单号" />
        </el-form-item>
        <el-form-item label="订单编号" prop="orderNum">
          <el-input v-model="form.orderNum" placeholder="请输入订单编号" />
        </el-form-item>
        <el-form-item label="公司电话" prop="telId">
          <el-input v-model="form.telId" placeholder="请输入公司电话" />
        </el-form-item>
        <el-form-item label="公司邮箱" prop="emailId">
          <el-input v-model="form.emailId" placeholder="请输入公司邮箱" />
        </el-form-item>
        <el-form-item label="编制" prop="createMen">
          <el-input v-model="form.createMen" placeholder="请输入编制" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listPartner } from '@/api/system/partner.js'
import { listPerchase, getPerchase, delPerchase, addPerchase, updatePerchase, cancelState, sureState } from "@/api/system/perchase";
import purchasedetail from "@/views/system/purchasedetail/index";
import purchaseInquiry from "@/views/system/purchaseInquiry/index";
import purchaseedit from "@/views/system/purchaseedit/index";

export default {
  name: "Purchase",

  dicts: ['order_state', 'invoice_state', 'boshien_emp'],



  data() {
    return {
      //订单状态
      stateList: [
        {
          id: 'purchase',
          name: '采购订单'
        },
        {
          id: 'draft',
          name: '询价单'
        },
        {
          id: 'cancel',
          name: '已取消'
        },
      ],
      // 供应商
      customerdata: [],
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 采购表格数据
      perchaseList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 编制时间范围
      daterangeDateOrder: [],
      // 编制时间范围
      daterangeDateApprove: [],
      // 编制时间范围
      daterangeDatePlanned: [],
      // 编制时间范围
      daterangeCreateDate: [],
      // 查询参数
      queryParams: {
        partnerName: null,
        pageNum: 1,
        pageSize: 20,
        name: null,
        origin: null,
        dateOrder: null,
        dateApprove: null,
        partnerId: null,
        currencyId: null,
        state: 'draft',
        notes: null,
        invoiceCount: null,
        invoiceStatus: null,
        pickingCount: null,
        datePlanned: null,
        amountUntaxed: null,
        amountTax: null,
        amountTotal: null,
        createUid: null,
        pickingTypeId: null,
        groupId: null,
        createDate: null,
        writeUid: null,
        writeDate: null,
        purchaseNum: null,
        orderNum: null,
        telId: null,
        emailId: null,
        createMen: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        name: [
          { required: true, message: "参考不能为空", trigger: "blur" }
        ],
        dateOrder: [
          { required: true, message: "订单日期不能为空", trigger: "blur" }
        ],
        partnerId: [
          { required: true, message: "供应商id不能为空", trigger: "blur" }
        ],
        currencyId: [
          { required: true, message: "Currency不能为空", trigger: "blur" }
        ],
        pickingTypeId: [
          { required: true, message: "Deliver To不能为空", trigger: "blur" }
        ],
      }
    };
  },
  created() {
    this.getList();
    this.customerList()
  },
  methods: {
    // 下拉框选择客户
    customerList() {
      listPartner(this.queryParams).then(res => {
        // console.log(res);
        this.customerdata = res.rows
        // console.log(this.customerdata);

      })
    },
    // 客户搜索
    customerfilterMethod(node, val) {

      // console.log('val', val, 'node', node)
      // console.log(node);
      const que = {
        name: node,
        pageSize: 100,
        supplier: 't'
      }
      // console.log(que);
      listPartner(que).then(res => {
        // console.log(res);
        this.customerdata = res.rows
      })
    },
    // 编辑采购订单
    EditSale(row) {
      const id = row.id
      this.$router.push({
        path: "/purchaseedit",
        component: purchaseedit,
        redirect: "noRedirect",
        hidden: false,
        alwaysShow: true,
        query: { listId: id },

      });

    },
    // 新增询价单
    AddIquirySheet() {
      this.$router.push({
        path: "/purchaseInquiry",
        component: purchaseInquiry,
        redirect: "noRedirect",
        hidden: false,
        alwaysShow: true,
        // query: { listId: 574 },
        query: {},

      });

    },
    // 取消采购售订单
    cancelState(row) {
      const id = row.id
      cancelState(id).then(res => {
        // console.log(res);
      })
      this.getList();
    },
    // 确认采购订单
    sureState(row) {
      const id = row.id
      sureState(id).then(res => {
        // console.log(res);
      })
      this.getList();
    },
    // 创建时间和创建人
    getcreatNow() {
      var date = new Date();
      var data1 = date.getFullYear() + '-' + (date.getMonth() + 1) + '-' + date.getDate();
      this.form.createDate = data1
      // console.log(this.form.createDate);
      this.form.createUid = this.$store.state.user.name
      this.form.writeDate = data1
      // console.log(this.form.updateTime);
      this.form.writeUid = this.$store.state.user.name
      // console.log(this.$store.state.user.name);
      return data1

    },
    // 更新时间和更新人
    getupdateNow() {
      var date = new Date();
      var data1 = date.getFullYear() + '-' + (date.getMonth() + 1) + '-' + date.getDate();
      this.form.writeDate = data1
      // console.log(this.form.updateTime);
      this.form.writeUid = this.$store.state.user.name
      // console.log(this.$store.state.user.name);
      return data1

    },
    /** 查询采购列表 */
    getList() {
      this.loading = true;
      this.queryParams.params = {};
      if (null != this.daterangeDateOrder && '' != this.daterangeDateOrder) {
        this.queryParams.params["beginDateOrder"] = this.daterangeDateOrder[0];
        this.queryParams.params["endDateOrder"] = this.daterangeDateOrder[1];
      }
      if (null != this.daterangeDateApprove && '' != this.daterangeDateApprove) {
        this.queryParams.params["beginDateApprove"] = this.daterangeDateApprove[0];
        this.queryParams.params["endDateApprove"] = this.daterangeDateApprove[1];
      }
      if (null != this.daterangeDatePlanned && '' != this.daterangeDatePlanned) {
        this.queryParams.params["beginDatePlanned"] = this.daterangeDatePlanned[0];
        this.queryParams.params["endDatePlanned"] = this.daterangeDatePlanned[1];
      }
      if (null != this.daterangeCreateDate && '' != this.daterangeCreateDate) {
        this.queryParams.params["beginCreateDate"] = this.daterangeCreateDate[0];
        this.queryParams.params["endCreateDate"] = this.daterangeCreateDate[1];
      }
      // console.log(this.queryParams);
      listPerchase(this.queryParams).then(response => {
        // console.log(response);
        this.perchaseList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 查询详情按钮
    getDetail(row) {
      const id = row.id
      // this.dialogVisible = true
      // const arr = {}
      // getOrder(id).then(res => {
      //   console.log(res);
      //   this.result = res.data
      //   // this.result2 = res.data[1]
      //   // console.log(this.result);
      // })
      this.$router.push({
        path: "/purchasedetail",
        component: purchasedetail,
        redirect: "noRedirect",
        hidden: false,
        alwaysShow: true,
        query: { listId: id },
      });

    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        partnerName: null,
        id: null,
        name: null,
        origin: null,
        dateOrder: null,
        dateApprove: null,
        partnerId: null,
        currencyId: null,
        state: null,
        notes: null,
        invoiceCount: null,
        invoiceStatus: null,
        pickingCount: null,
        datePlanned: null,
        amountUntaxed: null,
        amountTax: null,
        amountTotal: null,
        createUid: null,
        pickingTypeId: null,
        groupId: null,
        createDate: null,
        writeUid: null,
        writeDate: null,
        purchaseNum: null,
        orderNum: null,
        telId: null,
        emailId: null,
        createMen: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;

      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.daterangeDateOrder = [];
      this.daterangeDateApprove = [];
      this.daterangeDatePlanned = [];
      this.daterangeCreateDate = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加采购";
      this.getcreatNow()
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getPerchase(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改采购";
        this.getupdateNow()
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updatePerchase(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addPerchase(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除"' + row.name + '"的订单？').then(function () {
        return delPerchase(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => { });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/perchase/export', {
        ...this.queryParams
      }, `perchase_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
